<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        class="j-table-force-nowrap" >

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
           <a-dropdown>
                    <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
                    <a-menu slot="overlay">
                      <a-menu-item>
                        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                          <a>删除</a>
                        </a-popconfirm>
                      </a-menu-item>
                    </a-menu>
                  </a-dropdown>
        </span>

        <span slot="status" slot-scope="text, record">
          <div v-if="text==1">是</div>
          <div v-else>否</div>
        </span>

      </a-table>
    </div>

    <pmsProductMinimumQuantityModal ref="PmsProductMinimumQuantityModal"
                                    @ok="modalFormOk"></pmsProductMinimumQuantityModal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import PmsProductMinimumQuantityModal from './modules/PmsProductMinimumQuantityModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {getAction} from "../../api/manage";

export default {
  name: "PmsProductMinimumQuantityList",
  mixins: [JeecgListMixin],
  components: {
    PmsProductMinimumQuantityModal
  },
  data() {
    return {
      description: '起订配置表',
      productId: "",
      columns: [
        {
          title: '公司代码',
          align: "center",
          dataIndex: 'companyCode'
        },
        {
          title: '起订数量(箱)',
          align: "center",
          dataIndex: 'quantity'
        },
        {
          title: '是否启用',
          align: "center",
          dataIndex: 'status',
          scopedSlots: {customRender: 'status'},
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
        }
      ],
      url: {
        list: "/pms/pmsProductMinimumQuantity/list",
        delete: "/pms/pmsProductMinimumQuantity/delete",
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    getMain(productId) {
      this.productId = productId;
      this.loadData()
    },
    loadData() {
      getAction(this.url.list, {
          productId: this.productId
        }
      ).then((res) => {
        if (res.success) {
          this.dataSource = res.result
        } else {
          this.dataSource = null
        }
      })
    },
    handleAdd: function () {
      if (this.productId == "") {
        this.$message.warning("请先选择商品");
        return;
      }
      this.$refs.PmsProductMinimumQuantityModal.add(this.productId);
      this.$refs.PmsProductMinimumQuantityModal.title = "新增";
    },
    handleEdit: function (record) {
      this.$refs.PmsProductMinimumQuantityModal.edit(record);
      this.$refs.PmsProductMinimumQuantityModal.title = "编辑";
    },
    modalFormOk: function () {
      this.loadData();
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>